home *** CD-ROM | disk | FTP | other *** search
- /* Commlib - XTWindow */
- /* Aztec C compiler 1.06i */
- /* Lightspeed C compiler 2.01 */
-
-
- /* Copyright © 1985,1986 by small systems guild. All rights reserved. */
-
- #include <extender.h> /* include Extender and standard Toolbox headers */
-
- WindowPtr CreateWindow(wPtr,R,Title,wType,Visible,GoAwayBox,GrowBox,vScrollBar,hScrollBar)
- WindowRecord *wPtr;
- Rect *R;
- char *Title;
- int wType;
- Boolean Visible,GoAwayBox,GrowBox,vScrollBar,hScrollBar;
- {
- WData WD;
- WDHandle tempWDH;
-
- if ((wType < 0) || (wType > 23) ||
- ((wType > 4) && (wType < 16) && (wType != 8) && (wType != 12)))
- return(NULL); /* refuse unkown window type parameter */
-
- InitWData(&WD);
- wPtr = (WindowRecord *)NewWindow(wPtr,R,Title,FALSE,wType,NEG_ONE,GoAwayBox,NULL);
- if (!ValidPointer((Ptr)wPtr))
- return(NULL);
-
- tempWDH = (WDHandle)NewHandle((long)sizeof(WData));
- SetWRefCon(wPtr,tempWDH);
- if (!ValidHandle((Handle)tempWDH))
- return(NULL);
-
- (**tempWDH).sync1 = SYNC1VAL;
- (**tempWDH).sync2 = SYNC2VAL;
- SetWData((WindowPtr)wPtr,&WD);
-
- if (!Visible)
- return((WindowPtr)wPtr);
-
- ShowWindow(wPtr);
- SetPort(wPtr);
- SelectWindow(wPtr);
-
- return((WindowPtr)wPtr);
- }
-
- void InitWData(wDataPtr) /* initializes WData record to blank values */
- WData *wDataPtr;
- {
- if (ValidPointer((Ptr)wDataPtr)) {
- wDataPtr->windowPic = NULL;
- wDataPtr->TEH = NULL;
- wDataPtr->wList = NULL;
- wDataPtr->vScrollBar = NULL;
- wDataPtr->hScrollBar = NULL;
- wDataPtr->GrowBox = FALSE;
- wDataPtr->exceptFlags = NULL;
- wDataPtr->sync1 = NULL;
- wDataPtr->sync2 = NULL;
- wDataPtr->rsrv1 = NULL;
- wDataPtr->rsrv2 = NULL;
- wDataPtr->rsrv3 = NULL;
- wDataPtr->rsrv4 = NULL;
- wDataPtr->UsrRef1 = NULL;
- wDataPtr->UsrRef2 = NULL;
- }
- }
-
- void GetWData(wPtr,wDataPtr) /* copies WData struct for given window pointer */
- WindowPtr wPtr;
- WData *wDataPtr;
- {
- WDHandle WDtemp;
- int wType;
-
- if (ValidPointer((Ptr)wDataPtr)) {
- if (ValidPointer((Ptr)wPtr)) {
- wType = ((WindowPeek)wPtr)->windowKind;
- if ((wType >= 0) && (wType != dialogKind)) {/* not DA or dialog wind*/
- WDtemp = (WDHandle)GetWRefCon(wPtr);
- if (ValidHandle((Handle)WDtemp)) /* if the handle looks OK */
- if (ValidWData(*WDtemp)) { /* and the WData record is valid*/
- *wDataPtr = **WDtemp; /* copy into user's WData struct*/
- RETURN;
- }
- }
- }
- InitWData(wDataPtr); /* zero out all fields of WDataRecord */
- }
- }
-
- void SetWData(wPtr,wDataPtr) /* sets WData struct for window pointer */
- WindowPtr wPtr;
- WData *wDataPtr;
- {
- WDHandle WDtemp;
- int wType;
-
- if (ValidPointer((Ptr)wPtr) && ValidPointer((Ptr)wDataPtr)) {
- wType = ((WindowPeek)wPtr)->windowKind;
- if ((wType >= 0) && (wType != dialogKind)) {/* not DA or dlog wind */
- WDtemp = (WDHandle)GetWRefCon(wPtr);
- if (ValidHandle((Handle)WDtemp)) /* if handle looks OK */
- if (ValidWData(*WDtemp)) { /* and WData rec valid */
- wDataPtr->sync1 = SYNC1VAL; /* set sync fields */
- wDataPtr->sync2 = SYNC2VAL;
- **WDtemp = *wDataPtr; /* copy user's WData */
- RETURN;
- }
- }
- }
- }
-
- void KillWData(wPtr) /* disposes of a window's WData structure */
- WindowPtr wPtr;
- {
- WData WD;
-
- if (ValidPointer((Ptr)wPtr)) {
- GetWData(wPtr,&WD);
- if (ValidWData(&WD)) {
- if (ValidHandle((Handle)(WD.windowPic)))
- DisposHandle((Handle)WD.windowPic);
- DisposHandle((Handle)GetWRefCon(wPtr));
- SetWRefCon(wPtr,NULL);
- }
- }
- }
-
- void SetWPic(wPtr,thePic)
- WindowPtr wPtr;
- PicHandle thePic;
- {
- WData WD;
- Rect R;
-
- GetWData(wPtr,&WD);
- R = (**thePic).picFrame;
- if (WD.hScrollBar != NULL) {
- SetCtlMax(WD.hScrollBar,R.right);
- SetCtlMin(WD.hScrollBar,R.left);
- SetCtlValue(WD.hScrollBar,R.left);
- }
- if (WD.vScrollBar != NULL) {
- SetCtlMax(WD.vScrollBar,R.bottom);
- SetCtlMin(WD.vScrollBar,R.top);
- SetCtlValue(WD.vScrollBar,R.top);
- }
- WD.windowPic = thePic;
- SetWData(wPtr,&WD);
- InvalRect(&(wPtr->portRect)); /* causes window content to be updated */
- }
-
- void KillWindow(wPtr) /* disposes of WData, controls and closes window */
- WindowPtr wPtr;
- {
- WData WD;
-
- KillWData(wPtr);
- KillControls(wPtr);
- CloseWindow(wPtr);
- }
-
- Boolean ValidWData(WDptr)
- WData *WDptr;
- {
- if (ValidPointer((Ptr)WDptr)) { /* if pointer is potentially valid */
- if ((WDptr->sync1 == SYNC1VAL) && /* and sync values match */
- (WDptr->sync2 == SYNC2VAL))
- return(TRUE); /* then WData record is valid */
- }
-
- return(FALSE); /* else the WData pointer was bad */
- }
-
-